package com.smyhvae.animatordemo.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;
import com.smyhvae.animatordemo.R;
import com.smyhvae.animatordemo.adapter.ListViewAdapter;

/**
 * @author Lin·俊浩
 * @since 2017/9/28
 */

public class ListViewActivity extends AppCompatActivity{

    private String[] names = {"小鱼", "小妖", "小美", "小鬼", "小人",
            "小鱼", "小妖", "小美", "小鬼", "小人", "小鱼", "小妖", "小美", "小鬼", "小人"};
    private Integer[] imageIds = {R.drawable.len, R.drawable.leo, R.drawable.lep, R.drawable.ler, R.drawable.les,
            R.drawable.len, R.drawable.leo, R.drawable.lep, R.drawable.ler, R.drawable.les,
            R.drawable.len, R.drawable.leo, R.drawable.lep, R.drawable.ler, R.drawable.les};
    private ListView listView;
    private ListViewAdapter listViewAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);
        initView();
        listViewAdapter = new ListViewAdapter(this, names, imageIds);
        listView.setAdapter(listViewAdapter);
        listView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch(motionEvent.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        //触摸时操作
                        Log.d("Test", "ACTION_DOWN");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        //移动时操作
                        Log.d("Test", "ACTION_MOVE");
                        break;
                    case MotionEvent.ACTION_UP:
                        //离开时操作
                        Log.d("Test", "ACTION_UP");
                        break;
                }
                return false;
            }
        });

        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
                switch(i){
                    case AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
                        //滑动停止
                        Log.d("Test", "SCROLL_STATE_IDLE");
                        break;
                    case AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
                        //正在滚动
                        Log.d("Test", "SCROLL_STATE_TOUCH_SCROLL");
                        break;
                    case AbsListView.OnScrollListener.SCROLL_STATE_FLING:
                        //手指抛动时 即手指用力滑动
                        //在离开后ListView游湖惯性继续滑动
                        Log.d("Test", "SCROLL_STATE_FLING");
                        break;
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int i, int i1, int i2) {

            }
        });
    }

    private void initView(){
        listView = (ListView) findViewById(R.id.list_view);
    }
}
